import 'package:flutter/material.dart';
import 'package:razer_one/app/main/model/eventbus_model.dart';
import 'package:razer_one/app/main/utils/app_manager.dart';
import 'package:razer_one/app/main/view/main_btn.dart';
import 'package:razer_one/app/main/view/main_slide_cell.dart';

class DeletePage extends StatefulWidget {
  const DeletePage({Key? key}) : super(key: key);

  @override
  State<DeletePage> createState() => _DeletePageState();
}

class _DeletePageState extends State<DeletePage> with TickerProviderStateMixin {
  var dataArr = ["1", "2", "3", "4"];
  SlideCellModel model = SlideCellModel(index: 0);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("测试"),
      ),
      body: GestureDetector(
        onTap: () {
          model.index = -1;
          AppManager.instance.eventBus?.fire(model);
        },
        child: ListView.builder(
            itemCount: dataArr.length,
            itemBuilder: ((context, index) {
              return MainSlideCell(
                onSlideStarted: () {
                  model.index = index;
                  AppManager.instance.eventBus?.fire(model);
                },
                onSlideCanceled: () {
                  model.index = index;
                },
                child: Container(
                  color: Colors.white,
                  padding: EdgeInsets.all(15),
                  child: Text("$index"),
                ),
                buttons: [
                  MainTextBtn("置顶",
                      backgroundNormalColor: Colors.grey,
                      btnW: 80,
                      btnH: double.infinity, handle: () {
                    print("置顶$index");
                  }),
                  buildAction("标为未读", Colors.amber, () {}),
                  buildAction("删除", Colors.red, () {}),
                ],
                singleButtonWidth: 80,
                index: index,
              );
            })),
      ),
    );
  }

  InkWell buildAction(String text, Color color, GestureTapCallback tap) {
    return InkWell(
      onTap: tap,
      child: Container(
        alignment: Alignment.center,
        width: 80,
        height: null,
        color: color,
        child: Text(text,
            style: TextStyle(
              color: Colors.white,
            )),
      ),
    );
  }
}
